import CryptoJS from 'crypto-js'
async function sha256_HMAC(key, message) {
  return CryptoJS.HmacSHA256(message, key).toString();
}

async function getSign(accessKeySecret, timestamp, nonce) {
  const key = accessKeySecret;
  const message = accessKeySecret + timestamp + nonce;
  return await sha256_HMAC(key, message);
}

export async function getAccessParams() {
  const appKey = 'a8e27422bae64cd0ba24cb794b283de5'  //写死替换
  const secret = 'f3b2e1981c8649b7829727dafba08af8'  //写死替换
  const timestamp = Math.floor(Date.now() / 1000);
  const nonce = Math.random().toString(36).substring(2, 15);

  const sign = await getSign(secret, timestamp, nonce);

  const params = {
    appKey,
    timestamp,
    nonce,
    sign
  };
  return params;
}
